<template>
  <a-modal v-model:open="open" centered :width="props.width" :afterClose="doclose">
    <template #closeIcon>
      <div class="close">
        <i class="iconfont icon-guanbi"></i>
      </div>
    </template>
    <template #title>
      <div class="title-box">
        <div class="title"> {{ props.title }}</div>
      </div>
    </template>
    <template #footer>
      <div class="footer" v-if="props.showFooter">
        <Button color="#ABBACD" @click="open = false">取消</Button>
        <Button type="primary" @click="handleOk" :loading='props.loading'>确定</Button>
      </div>
    </template>
    <div class="content">
      <slot name="content"></slot>
    </div>
  </a-modal>
</template>

<script setup lang='ts'>
import { ref, watch, nextTick } from "vue"
import { Button } from '@/components/Button';

const props = defineProps({
  width: {
    default: "40%",
    required: false,
  },
  title: {
    default: "",
    required: false,
  },
  show: {
    default: false,
    required: true,
  },
  showFooter: {
    default: true,
  },
  widthComfirm: {
    default: false
  },
  loading:{
    default: false,
    required: false,
  }
})
const open = ref<boolean>(false);
const emits = defineEmits(['comfirm', 'closeModal','close'])
watch(() => props.show, (val) => {
  open.value = val
}, {
  immediate: true
})

const doclose =()=>{
  open.value =false;
  console.log('close is invoke')
  emits('close')
}
watch(open, (val) => {
  if (!val) {
    emits('closeModal')
  }
})
const handleOk = () => {
  if (props.widthComfirm) {
    emits('comfirm')
    return
  }
  open.value = false
}
</script>

<style lang="less" scoped>
.title-box {
  height: 56px;
  line-height: 56px;
  background: #F5F7FB;
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}

.footer {
  text-align: center;
  height: 40px;
  margin-top: 10px;
}

.content {
  width: 100%;
  min-height: 100px;
  margin-top: 44px;
  padding: 0 20px;
  box-sizing: border-box;
  padding-top: 20px;
}
</style>